<?php require 'header.php';?>
<?php
require 'db.php';
//==========================
$dsdk=array();
$sqlds="SELECT dbo_monhoc.MAMH,dbo_monhoc.TENMH,dbo_noidung.MANHOM,dbo_noidung.TENNHOM,dbo_sinhvien.MASV,concat(dbo_sinhvien.Holot,' ',dbo_sinhvien.Ten) as HOTEN,dbo_sinhvien.MALOP,dbo_sinhvien.EMAIL,dbo_dondangky.SDTDK";
$sqlds.=" FROM dbo_dondangky, dbo_monhoc, dbo_sinhvien, dbo_noidung";
$sqlds.=" WHERE dbo_sinhvien.MASV = dbo_dondangky.MASV
AND dbo_dondangky.MANHOM=dbo_noidung.MANHOM
AND dbo_monhoc.MAMH=dbo_noidung.MAMH";
$stmt = $db->prepare($sqlds);
$stmt->execute();
	if($stmt->execute()){
		while($r=$stmt->fetch()){
			$dsdk=array_merge($dsdk,array(
					array("MAMH"=> $r['MAMH'],"TENMH"=> $r['TENMH'],"MANHOM" => $r['MANHOM'],"TENNHOM"=>$r['TENNHOM'],"MASV"=>$r['MASV'],"HOTEN"=>$r['HOTEN'],"MALOP"=>$r['MALOP'],"EMAIL"=>$r['EMAIL'],"SDTDK"=>$r['SDTDK'])
			));
		}}
//=============Ham kt
$kiemtra=array();
$sqlkt="SELECT dbo_monhoc.MAMH,dbo_monhoc.TENMH,dbo_noidung.MANHOM,dbo_noidung.TENNHOM,dbo_sinhvien.MASV,dbo_sinhvien.MALOP,dbo_sinhvien.EMAIL,dbo_noidung.SiSoToiDa,dbo_noidung.SiSoToiDa-count(dbo_dondangky.MASV) as SLCL
";
$sqlkt.=" FROM dbo_dondangky, dbo_monhoc, dbo_sinhvien, dbo_noidung";
$sqlkt.=" WHERE dbo_sinhvien.MASV = dbo_dondangky.MASV
AND dbo_dondangky.MANHOM=dbo_noidung.MANHOM
AND dbo_monhoc.MAMH=dbo_noidung.MAMH group by MANHOM";
$stmt = $db->prepare($sqlkt);
$stmt->execute();
	if($stmt->execute()){
		while($r1=$stmt->fetch()){
			$kiemtra=array_merge($kiemtra,array(
					array("MAMH"=> $r1['MAMH'],"TENMH"=> $r1['TENMH'],"MANHOM" => $r1['MANHOM'],"TENNHOM"=>$r1['TENNHOM'],"MASV"=>$r1['MASV'],"MALOP"=>$r1['MALOP'],"EMAIL"=>$r1['EMAIL'],"SiSoToiDa"=>$r1['SiSoToiDa'],"SLCL"=>$r1['SLCL'])
			));
		}}
//=========================================================
//=========================================================đội
$dsdkd=array();
$sqldsd="SELECT dbo_noidung.MANHOM,dbo_monhoc.MAMH,dbo_monhoc.TENMH,dbo_noidung.TENNHOM,dbo_dongdoi.MADOI,dbo_dongdoi.TENDOI,dbo_sinhvien.MASV,concat(dbo_sinhvien.Holot,' ',dbo_sinhvien.Ten) as HOTEN,dbo_sinhvien.MALOP,dbo_sinhvien.EMAIL,dbo_doidangky.SDTDK";
$sqldsd.=" FROM dbo_doidangky, dbo_noidung, dbo_sinhvien, dbo_dongdoi,dbo_monhoc";
$sqldsd.=" WHERE dbo_sinhvien.MASV = dbo_doidangky.MASV
AND dbo_doidangky.MADOI=dbo_dongdoi.MADOI
AND dbo_noidung.MANHOM=dbo_dongdoi.MANHOM 
AND dbo_monhoc.MAMH=dbo_noidung.MAMH";
$stmtd = $db->prepare($sqldsd);
$stmtd->execute();
	if($stmtd->execute()){
		while($rd=$stmtd->fetch()){
			$dsdkd=array_merge($dsdkd,array(
					array("MANHOM"=> $rd['MANHOM'],"MAMH"=> $rd['MAMH'],"TENMH"=> $rd['TENMH'],"TENNHOM"=> $rd['TENNHOM'],"MADOI" => $rd['MADOI'],"TENDOI"=>$rd['TENDOI'],"MASV"=>$rd['MASV'],"HOTEN"=>$rd['HOTEN'],"MALOP"=>$rd['MALOP'],"EMAIL"=>$rd['EMAIL'],"SDTDK"=>$rd['SDTDK'])
			));
		}}
//=============Ham kt
$kiemtradoi=array();
$sqlktdoi="SELECT dbo_noidung.MANHOM,dbo_monhoc.MAMH,dbo_monhoc.TENMH,dbo_noidung.TENNHOM,dbo_dongdoi.MADOI,dbo_dongdoi.TENDOI,dbo_sinhvien.MASV,dbo_sinhvien.MALOP,dbo_sinhvien.EMAIL,dbo_dongdoi.SLToiDa,dbo_dongdoi.SLToiDa-count(dbo_doidangky.MASV) as SLCL";
$sqlktdoi.=" FROM dbo_doidangky, dbo_noidung, dbo_sinhvien, dbo_dongdoi,dbo_monhoc";
$sqlktdoi.=" WHERE dbo_sinhvien.MASV = dbo_doidangky.MASV
AND dbo_doidangky.MADOI=dbo_dongdoi.MADOI
AND dbo_noidung.MANHOM=dbo_dongdoi.MANHOM 
AND dbo_monhoc.MAMH=dbo_noidung.MAMH group by MADOI";
$stmt = $db->prepare($sqlktdoi);
$stmt->execute();
	if($stmt->execute()){
		while($r1=$stmt->fetch()){
			$kiemtradoi=array_merge($kiemtradoi,array(
					array("MAMH"=> $r1['MAMH'],"TENMH"=> $r1['TENMH'],"MANHOM" => $r1['MANHOM'],"TENNHOM"=>$r1['TENNHOM'],"MASV"=>$r1['MASV'],"MALOP"=>$r1['MALOP'],"EMAIL"=>$r1['EMAIL'],"SLToiDa"=>$r1['SLToiDa'],"SLCL"=>$r1['SLCL'])
			));
		}}

//=============================================================
?>
<div class="panel panel-primary">
	<div class="panel-heading">DANH SÁCH SINH VIÊN ĐÃ ĐĂNG KÝ</div>
	<div class="panel-body">
	<div id="divDMHP">
	<div id="divKQHT">
			<a href="javascript:window.print()">In Trang Này</a>
			<table  class="table table-bordered table-hover" style="font-size: 13px;">
			<?php foreach($kiemtra as $kt){?>
			<?php $i=0;?>
			<thead><tr>
				<th colspan="2" bgcolor="#00CCFF">
				<?php	
								echo "MÔN THỂ THAO : ".$kt['TENMH'];							
				?>
				</th>
							<th colspan="2" bgcolor="#00CCFF">
				<?php	
								echo "NỘI DUNG:".$kt['TENNHOM'];							
				?>
				</th>			<th colspan="1" bgcolor="#00CCFF">
				<?php	
								echo "Số lượng:".$kt['SiSoToiDa'];							
				?>
				</th>
				</th>			<th colspan="1" bgcolor="#00CCFF">
				<?php	
								echo "Còn lại: ".$kt['SLCL'];							
				?>
				</th>
			</tr></thead>
			<thead><tr class="info"><th>STT</th><th>MASV</th><th>HOTEN</th><th>LỚP</th><th>Số điện thoại</th><th>EMAIL</th></tr></thead>
			<?php foreach($dsdk as $dsdks){ 
					if($kt['MANHOM']==$dsdks['MANHOM']){
					$i++;		
			?>
			<tbody>
				<tr>
				<td><?php echo $i ?></td>
				<td><?php echo $dsdks['MASV'];?></td>
				<td><?php echo $dsdks['HOTEN'];?></td>
				<td><?php echo $dsdks['MALOP'];?></td>
				<td><?php echo $dsdks['SDTDK'];?></td>
				<td><?php echo $dsdks['EMAIL'];?></td>
			  </tr>
			</tbody>
			<?php }}}?>
			<!--===========================================================-->
			<?php foreach($kiemtradoi as $kt){ ?>
			
			<thead><tr>
				<th colspan="2" bgcolor="#00CCFF">
				<?php	
								echo "MÔN THỂ THAO : ".$kt['TENMH'];							
				?>
				</th>
							<th colspan="2" bgcolor="#00CCFF">
				<?php	
								echo "NỘI DUNG:".$kt['TENNHOM'];							
				?>
				</th>			<th colspan="1" bgcolor="#00CCFF">
				<?php	
								echo "Số lượng:".$kt['SLToiDa'];							
				?>
				</th>
				</th>			<th colspan="1" bgcolor="#00CCFF">
				<?php	
								echo "Còn lại: ".$kt['SLCL'];							
				?>
				</th>
			</tr></thead>
			<thead><tr class="info"><th>STT</th><th>MASV</th><th>Họ Tên</th><th>LỚP</th><th>Số điện thoại</th><th>EMAIL</th></tr></thead>
			<?php foreach($dsdkd as $dsdksd){ 
					if($kt['MANHOM']==$dsdksd['MANHOM']){		
			$i++;
			?>
			<tbody>
				<tr>
				<td><?php echo $i;?></td>
				<td><?php echo $dsdksd['MASV'];?></td>
				<td><?php echo $dsdksd['HOTEN'];?></td>
				<td><?php echo $dsdksd['MALOP'];?></td>
				<td><?php echo $dsdksd['SDTDK'];?></td>
				<td><?php echo $dsdksd['EMAIL'];?></td>
			  </tr>
			</tbody>
			<?php }}}?>
			<!--===========================================================-->
			</table>
		 	</div>
	</div>
	</div>
</div>
<?php require 'footer.php';?>
